package com.xumz.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xumz.controller.param.BlogParam;
import com.xumz.controller.tool.IDFactoty;
import com.xumz.dao.TeacherDao;
import com.xumz.model.Teacher;
import com.xumz.service.TeacherService;

@Service
public class TeacherServiceImpl implements TeacherService {

	@Autowired
	private TeacherDao teacherDao;

	@Override
	public Teacher selectOne(String id) {
		return teacherDao.selectOne(id);
	}

	@Override
	public int insertOne(Teacher teacher) {
		teacher.setId(IDFactoty.productIdByDateTime());
		System.out.println(teacher.toString());
		return teacherDao.insertOne(teacher);
	}
	
	public int loginService(String id,String pwd){
		Teacher teacher=teacherDao.selectOne(id);
		if (teacher==null) {
			return BlogParam.LONING_USER_NO_EXIT;
		}
		if (!teacher.getPwd().equals(pwd)) {
			return BlogParam.LONING_USER_ERROR_PWD;
		}
		return 0;
	}

	@Override
	public int registerService(Teacher teacher) {
		Teacher bean=teacherDao.selectOne(teacher.getName());
		if (bean!=null) {
			return BlogParam.REGISTER_USERNAME_REPEAT;
		}
		teacher.setId(IDFactoty.productIdByDateTime());
		teacherDao.insertOne(teacher);
		return 0;
	}

	@Override
	public int validateName(String name) {
		Teacher bean=teacherDao.selectOne(name);
		if (bean!=null) {
			return BlogParam.REGISTER_USERNAME_REPEAT;
		}
		return 0;
	}
	
	
}
